package com.leyou.item.service;

import com.leyou.item.mapper.CategoryMapper;
import com.leyou.item.pojo.Category;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;

    /**
     * 根据parentId查询子类目
     * @param pid
     * @return
     */
    public List<Category> queryCategoriesByPid(Long pid){
        Category category = new Category();
        category.setParentId(pid);

        return this.categoryMapper.select(category);
    }

    /**
     * 根据品牌id查询商品分类
     * @param bid
     * @return
     */
    public List<Category> queryByBrandId(Long bid) {

     return  this.categoryMapper.queryByBrandId(bid);
    }

    /**
     * 根据多个分类id查询分类
     * @param ids
     * @return
     */
    public List<String> queryNameById(List<Long> ids){

        List<Category> categories = this.categoryMapper.selectByIdList(ids);

        List<String> names = new ArrayList<>();
        for (Category category : categories
             ) {
            names.add(category.getName());

        }
        return names;
    }


}
